package com.example.demo.service.Impl;

import com.example.demo.bean.Dataset;
import com.example.demo.bean.DatasetExample;
import com.example.demo.dao.DatasetMapper;
import com.example.demo.service.IDatasetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;

@Service
public class DatasetServiceImpl implements IDatasetService {
    @Autowired
    private DatasetMapper datasetMapper;
    @Override
    public List<Dataset> query(String name) {
        DatasetExample example = new DatasetExample();
        if (!StringUtils.isEmpty(name)) {
            example.createCriteria().andNameLike("%" + name + "%");
        }
        return datasetMapper.selectByExample(example);
//        if (!StringUtils.isEmpty(id)) {
//            example.createCriteria().andIdEqualTo(id);
//        }
//        List<Dataset> list = datasetMapper.selectByExample(example);
//        return list;
    }

    @Override
    public void saveOrUpdate(Dataset dataset) {
        if(dataset.getId()==null){

            datasetMapper.insert(dataset);
        }else{
            datasetMapper.updateByPrimaryKey(dataset);
        }


    }

    @Override
    public void deleteById(long id) {
        datasetMapper.deleteByPrimaryKey(id);
    }

}
